package com.demo.controller;


import java.util.List;

import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.dto.SessionWebUserDto;
import com.demo.entity.po.Comment;

import com.demo.entity.query.CommentQuery;


import com.demo.entity.vo.ResponseVO;

import com.demo.service.CommentService;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


/**
 * @Description:Controller
 * @Date:2025-02-28
 * @author：author
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends ABaseController {

	@Resource
	private CommentService commentService;



	/**
	 * 查询评论列表
	 */
	@RequestMapping("/loadCommentList")
	@GlobalInterceptor(checkLogin = false)
	public ResponseVO loadDataList(CommentQuery query) {
		List<Comment> commentsList = commentService.findCommentsList(query);
		return getSuccessResponseVO(commentsList);
	}

	/**
	 * 添加评论
	 * @param session
	 * @param comments
	 * @return
	 */
	@RequestMapping("/saveComment")
	@GlobalInterceptor
	public ResponseVO saveComments(HttpSession session, Comment comments) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		comments.setUserId(webUserDto.getUserId());
		commentService.saveComments(comments);
		return getSuccessResponseVO(null);
	}


	/**
	 * 根据id 删除
	 * @param session
	 * @param commentId
	 * @return
	 */
	@RequestMapping("/delComment")
	@GlobalInterceptor
	public ResponseVO delComment(HttpSession session, @VerifyParam(required = true) Long commentId) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		commentService.delComment(webUserDto.getUserId(),commentId);
		return getSuccessResponseVO(null);
	}


}